Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Valor de Javascript JSON obj "indefinido"

Oye, recibo esta respuesta consulta una API con búsqueda de nodo:

 { 'access-control-allow-credentials': 'true', 'access-control-allow-headers': 'Origin, Content-Type, Accept, Authorization, X-Request-With, Webpunch-App-Version, X-timezone, X-token', 'access-control-allow-methods': 'POST, GET, OPTIONS, PUT, DELETE', 'access-control-allow-origin': 'censored', 'access-control-max-age': '86400', 'cache-control': [ 'no-store, no-cache, must-revalidate', 'no-cache, private' ], 'content-encoding': 'gzip', 'content-type': 'application/json', date: 'Sun, 29 May 2022 13:04:49 GMT', expires: 'Thu, 19 Nov 1981 08:52:00 GMT', pragma: 'no-cache', 'set-cookie': [ 'QWFMSESSION=censored; path=/; secure; HttpOnly', 'api_session=meJMkISigaS2dcHK7kKBzFjWyY4zHiQHnyKOiix4; expires=Sun, 05-Jun-2022 13:04:49 GMT; Max-Age=604800; path=/; secure; httponly; samesite=lax' ], 'strict-transport-security': 'max-age=15724800; includeSubdomains; preload', 'transfer-encoding': 'chunked', vary: 'Accept-Encoding', 'x-content-type-options': 'nosniff', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block' }

Y desea obtener el valor del token 'api_session'. Cuando trato de usar result['set-cookie'] devuelve indefinido. Cuando intento usar JSON.parse(JSON.stringify(result)) devuelve una matriz en blanco. Pero cuando copio el resultado y lo pego en otro archivo js, funciona sin problemas... aquí está mi código:

 fetch('censored', { method: 'POST', headers: { censored }, body: censored }) .then(async (res) => { return [await res.json(), res.headers]; }) .then(([jsonData, result]) => { console.log(result['set-cookie']) }) .catch((err) => { // handle error console.error(err); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

fetch('') .then(async (res) => { return [await res.json(), res.headers]; }) .then(([jsonData, result]) => { console.log(jsonData['set-cookie']) }) .catch((err) => { // handle error console.error(err); });

Necesitas leer desde jsonData y no desde el resultado

El resultado contiene encabezados de solicitud

Si quieres obtener api-session desde el encabezado, prueba esto

 fetch('') .then(async (res) => { return [await res.json(), res.headers]; }) .then(([jsonData, result]) => { console.log(result.get('api_session')) }) .catch((err) => { // handle error console.error(err); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!